<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>导入用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script src="../js/base.js"></script>
    <script src="../js/jquery.min.js"></script>
</head>

<body>

    <div style="padding:20px">
        <div style="margin-left: 20px;margin-bottom: 20px;">
            <i class="layui-icon">&#xe67c;</i>
            <span>下载模板</span>
        </div>
        <span style="margin-left: 40px;padding-bottom:32px">为提高导入的成功率，请下载并使用系统提供的模板</span><br>
        <button style="margin-left: 40px;margin-top:20px" class="layui-btn downLoadModel">下载模板</button>
    </div>
    <div style="padding:20px">
        <div style="margin-left: 20px;margin-bottom: 20px;">
            <i class="layui-icon">&#xe67c;</i>
            <span>上传文件</span>
        </div>
        <span style="margin-left: 40px;padding-bottom:32px">仅支持xlsx,xls,文件大小≤4M</span><br>
        <div style="display: flex;margin-top:10px;width: 440px;">
            <input type="text" class="layui-input" id="fileName" placeholder="上传文件" style="margin:0 32px" id="test2">
            <button type="button" class="layui-btn" id="test1">选择文件</button>
        </div>
    </div>
    <div style="text-align: center;">
        <button class="layui-btn" id="testListAction">开始导入</button>
    </div>
    <script src="../js/export.js"></script>
    <script>
        layui.use('upload', function () {
            var upload = layui.upload;

            //执行实例
            var uploadInst = upload.render({
                elem: '#test1',
                url: uploadMatchReferee, //导入
                method: "post",
                accept: "file", //允许上传的文件类型
                exts: 'xlsx|xls', //上传的文件后缀.只能是xlsx和xls格式
                size: 4 * 1024, //设置文件最大可允许上传的大小，单位 KB
                auto: false, //选择文件后不自动上传
                bindAction: '#testListAction', //指定一个按钮触发上传
                choose: function (obj) {
                    // //将每次选择的文件追加到文件队列
                    console.log(obj, '选择的用户上传文件')
                    // var files = obj.pushFile();
                    var flag = true;
                    //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                    obj.preview(function (index, file, result) {
                        // console.log(index); //得到文件索引
                        console.log(file); //得到文件对象
                        // console.log(result); //得到文件base64编码，比如图片
                        $("#fileName").val(file.name)
                    });
                },
                before: function (obj) {
                    layer.load();
                },
                //上传接口 //绑定元素
                done: function (res) {
                    //上传完毕回调
                    layer.closeAll('loading');
                    console.log(res, '批量上传用户上传')
                    if (res.msg == 0) {
                        //do something （比如将res返回的图片链接保存到表单的隐藏域）
                        layer.alert('导入成功', {
                            title: '提示',
                            cancel: function () {
                                for (var i = 0; i < res.data.length; i++) {
                                    parent.arry.push(res.data[i])
                                }

                                parent.render()
                                var index = parent.layer.getFrameIndex(window
                                    .name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            }
                        }, function () {
                            for (var i = 0; i < res.data.length; i++) {
                                console.log(parent.arry)
                                parent.arry.push(res.data[i])
                            }

                            parent.render()
                            var index = parent.layer.getFrameIndex(window
                                .name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        })
                    } else {
                        layer.msg(res.msg)
                    }
                },
                error: function () {
                    //请求异常回调
                    layer.closeAll('loading');
                    layer.msg('网络异常，请稍后重试！');
                }
            });
        });
        // 下载模板
        $(".downLoadModel").on("click", function () {
            window.location.href = downloadMatchExcelTemplate
        })
    </script>
</body>

</html>